define(["jQuery", "kendo","../menu/nicEdit"], function ($, kendo, nicEdit) {
 	return {
    	creationMode:false,
		panelToolbox:false,
		colorText1:false,
		colorText2:false,
		textBackground1:false,
		colorBackground2:false,
		colorShadow:false,
		checkGradChar:0,
		checkGradBack:0,
		checkTransChar:0,
		isBold:0,
		isItalic:0,
		isUnderline:0,
		checkVert:0,
		show : function(){
			// $( "#text-logo-dragable-menu").offset({ top: App.lastClickGlobalPoint.y, left: App.lastClickGlobalPoint.x});
			$( "#text-logo-dragable-menu").css('left', App.lastClickPointTools.x);
			$( "#text-logo-dragable-menu").css('top', App.lastClickPointTools.y);
			
			$( "#text-logo-dragable-menu").show();			
		},
		
        init: function (e) {
			console.log("init text-logo ...");
			$("#text-logo-dragable-menu").draggable();
			$("#text-logo-dragable-menu").hide();
			// $("#gradChar").hide();
			
			var textareas = document.getElementsByTagName("textarea");

			$('#colorText1').jPicker(
					{
					 window:
						  {
							expandable: true
						  },
						  images:
						  {
							clientPath : App.baseUrl+'assets/css/images/jPicker/'
						  }
					},
					function(color, context)
					{
					  var all = color.val('all'); 
						App.textLogoToolbox.colorText1 =  '#' + all.hex;				
					}
			);
			$('#colorText2').jPicker(
					{
					 window:
						  {
							expandable: true
						  },
						  images:
						  {
							clientPath : App.baseUrl+'assets/css/images/jPicker/'
						  }
					},
					function(color, context)
					{
					  var all = color.val('all'); 
						App.textLogoToolbox.colorText2 = '#' + all.hex;				
					}
			);
			
			$('#textBackground1').jPicker(
					{
					 window:
						  {
							expandable: true
						  },
						  images:
						  {
							clientPath : App.baseUrl+'assets/css/images/jPicker/'
						  }
					},
					function(color, context)
					{
					  var all = color.val('all'); 
						App.textLogoToolbox.textBackground1 = '#' + all.hex;	
					}
			);
			$('#colorBackground2').jPicker(
					{
					 window:
						  {
							expandable: true
						  },
						  images:
						  {
							clientPath : App.baseUrl+'assets/css/images/jPicker/'
						  }
					},
					function(color, context)
					{
					  var all = color.val('all'); 
						App.textLogoToolbox.colorBackground2 = '#' + all.hex;				
					}
			);
			$('#colorShadow').jPicker(
					{
					 window:
						  {
							expandable: true
						  },
						  images:
						  {
							clientPath : App.baseUrl+'assets/css/images/jPicker/'
						  }
					},
					function(color, context)
					{
					  var all = color.val('all'); 
						App.textLogoToolbox.colorShadow = '#' + all.hex;			
					}
			);
			
			// for(var i=0;i<textareas.length;i++)
			 // {
				// var myNicEditor = new nicEditor();
				// myNicEditor.setPanel('nic-edit-panel-logo');
				// myNicEditor.addInstance(textareas[i]);
				// $('#area-text-logo').css('display', 'block');
				// $('#area-text-logo').attr('class', 'nicEdit-main'); 
			 // }
			// App.textLogoToolbox.panel = new nicEditor({buttonList : ['bold','italic','underline','fontSize','fontFormat','fontFamily']},{iconsPath : 'nicEditorIcons.gif'}).addInstance('area-text-logo');
			// App.textLogoToolbox.panel = new nicEditor().addInstance('area-text-logo');
			 	// App.textLogoToolbox.panel.setPanel('nic-edit-panel-logo');
			 // App.textLogoToolbox.panel.addInstance('area-text-logo');
		
			// App.textLogoToolbox.panelToolbox.setPanel('divText');
			// App.textLogoToolbox.panelToolbox.addInstance('area-text-logo');
			// $('#area-text-logo').css('display', 'block');
			// bkLib.onDomLoaded(function() {
				// nicEditors.editors.push(
					// new nicEditor({buttonList : ['bold','italic',' ',' ',' ',' ','underline','fontFormat', 'fontFamily','fontSize']}).panelInstance(
						// document.getElementById('divText')
					// ) 
				// );
			// });
			$('#btnBoldTextLogo').click(function() { 
				if(App.textLogoToolbox.isBold == 0){
					$("#btnBoldTextLogo").attr('src', App.baseUrl+'assets/css/images/text_bold_down.png');
					App.textLogoToolbox.isBold = 1;
				}else{
					$("#btnBoldTextLogo").attr('src', App.baseUrl+'assets/css/images/text_bold.png');
					App.textLogoToolbox.isBold = 0;
				}
			});
			$('#btnItalicTextLogo').click(function() { 
				if(App.textLogoToolbox.isItalic == 0){
					$("#btnItalicTextLogo").attr('src', App.baseUrl+'assets/css/images/text_italic_down.png');
					App.textLogoToolbox.isItalic = 1;
				}else{
					$("#btnItalicTextLogo").attr('src', App.baseUrl+'assets/css/images/text_italic.png');
					App.textLogoToolbox.isItalic = 0;
				}
			});
			$('#btnUnderlineTextLogo').click(function() { 
				if(App.textLogoToolbox.isUnderline == 0){
					$("#btnUnderlineTextLogo").attr('src', App.baseUrl+'assets/css/images/text_under_down.png');
					App.textLogoToolbox.isUnderline = 1;
				}else{
					$("#btnUnderlineTextLogo").attr('src', App.baseUrl+'assets/css/images/text_under.png');
					App.textLogoToolbox.isUnderline = 0;
				}
			});
			
			$('#area-text-logo').click(function() {
				//App.textLogoToolbox.panel.addInstance('area-text-logo');
				$("#text-logo-dragable-menu").draggable('disable');
			});
			$(".text-logo-tools").click(function() {
				if(App.isModeArea == 1){
					App.setEnableTextLogoCreationMode(true);
				}else{
					alert(App.localize("%view_mode_warning_dialog"));
				}
			});
			$('#text-area').on( 'click', function (e) {  
				$(this).focus();
			});
			$('#btnRot').on( 'click', function (e) {  
				$( "#initial-rotation-dragable-menu").css('left', App.lastClickPointTools.x);
				$( "#initial-rotation-dragable-menu").css('top', App.lastClickPointTools.y);
				
				$( "#initial-rotation-dragable-menu").show();
				$( "#initial-rotation-dragable-menu").draggable();
			});
			$(".submit-input-text").click(function() { 
				$( "#text-logo-dragable-menu" ).hide(); 
				  
				
				if(!$('#checkGradChar').attr("checked")){
					App.textLogoToolbox.colorText2 = App.textLogoToolbox.colorText1;
					App.textLogoToolbox.checkGradChar = 0;
				}else{
					App.textLogoToolbox.checkGradChar = 1;
				}
				
				if(!$('#checkGradBack').attr("checked")){
					App.textLogoToolbox.colorBackground2 = App.textLogoToolbox.textBackground1;
					App.textLogoToolbox.checkGradBack = 0;
				}else{
					App.textLogoToolbox.checkGradBack = 1;
				}
				
				if($('#checkTransChar').attr("checked")){
					App.textLogoToolbox.checkTransChar = 1;
				}else{
					App.textLogoToolbox.checkTransChar = 0;
				}
				
				if($('#checkVert').attr("checked")){
					App.textLogoToolbox.checkVert = 1;
				}else{
					App.textLogoToolbox.checkVert = 0;
				}
				
				// alert($("#fontSize").val());
				
				console.log($('#area-text-logo'));
				
				$('#tesDiv').css('font-family', $("#fontStyle").val());
				$('#tesDiv').css('font-size', $("#fontSize").val()+'pt'); 
 				$('#tesDiv').html($('#area-text-logo').val());
				$('#tesDiv').css('position','absolute');
				$('#tesDiv').css('display','none');
				// alert($('#tesDiv').width());
				 
				App.textToImage(App.lastClickPointTools.x, App.lastClickPointTools.y, $('#area-text-logo').val(),App.textLogoToolbox.colorText1,App.textLogoToolbox.colorText2,App.textLogoToolbox.textBackground1,App.textLogoToolbox.colorBackground2,App.textLogoToolbox.colorShadow, App.textLogoToolbox.checkTransChar, App.textLogoToolbox.isBold, App.textLogoToolbox.isItalic, App.textLogoToolbox.isUnderline, $("#fontStyle").val(), $("#fontSize").val(),App.textLogoToolbox.checkGradChar,App.textLogoToolbox.checkGradBack,$("#gradChar").val(),$("#gradBack").val(), $('#tesDiv').width(), $('#tesDiv').height()*2, App.textLogoToolbox.checkVert,$('#chooseShad').val(),$('#chooseWidthShad').val());
				
				$("#text-logo-dragable-menu").draggable('enable');
			});
			
			$(".cancel-text-logo-button").click(function() {
				var r=confirm(App.localize("%cancel_confirmation"));
				if (r==true)
				{
					$( "#text-logo-dragable-menu" ).hide();
					App.setEnableTextLogoCreationMode(false,"");
				}
				else
				{
					console.log("You pressed Cancel!");
				}
			});		
		
		}
	}
});